/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.dao.student;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import edu.uwm.universitydb.model.Student;

/**
 * <code>SearchStudentBySSNCommand</type>
 * Command class to fetch a student based on SSN
 * 
 * @author Shyam Nair
 */
public class SearchStudentBySSNCommand extends SearchStudentCommandBase<Student>
{

    /** sql portion representing where clause for name */
    private static final String SQL_WHERE_CLAUSE_NAME = " where grad_ssn = ?";

    /** attribute holding the ssn */
    private final String mSSN;

    /**
     * 
     * @param ssn
     */
    public SearchStudentBySSNCommand(final String ssn)
    {
        mSSN = ssn;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DataFetchCommand#processResult(java.sql.ResultSet)
     */
    @Override
    public Student processResult(final ResultSet result) throws SQLException
    {
        if (result.next())
        {
            return getStudent(result);
        }
        return null;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return SELECT_SQL + SQL_WHERE_CLAUSE_NAME;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        pStmt.setString(1, mSSN);
    }

}

/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 19, 2014   <TODO Enter your name here>
 * File created
 * ----------------------------------------------------------------------------
 */